package com.gjm.order.controller;

import com.gjm.product.api.ProductServiceApi;
import com.gjm.product.model.ProductInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/feign")
@RestController
public class FeignController {

    @Autowired
    private ProductServiceApi productServiceApi;

    /**
     * @RequestParam 注解注解中若指明了参数名称，前端在调用这个方法时，就需要使用注解中的参数名来传递参数
     * @param id
     * @return
     */
    @RequestMapping("/m1")
    public String m1(@RequestParam("id") Integer id) {
        log.info("m1_id: {}", id);
        return productServiceApi.method1(id);
    }

    @RequestMapping("/m2")
    public String m2(@RequestParam("id") Integer id,
                     @RequestParam("name") String name) {
        return productServiceApi.method2(id, name);
    }

    @RequestMapping("/m3")
    public String m3() {
        ProductInfo productInfo = new ProductInfo();
        productInfo.setId(12);
        productInfo.setProductName("aaa");
        return productServiceApi.method3(productInfo);
    }

    @RequestMapping("/m4")
    public String m4() {
        ProductInfo productInfo = new ProductInfo();
        productInfo.setId(12);
        productInfo.setProductName("aaa");
        return productServiceApi.method3(productInfo);
    }

}
